package main

import (
	"fmt"
	"github.com/go-redis/redis"
	"time"
)

var client *redis.Client

func init() {
	//初始化redis，连接地址和端口，密码，数据库名称
	client = redis.NewClient(&redis.Options{
		Addr:         "192.168.11.5:6379",
		Password:     "123456",
		DB:           0,
		PoolSize:     10, //最大连接数 默认 10 * runtime.NumCPU
		MinIdleConns: 3,  //启动后长期维护3个链接
	})
}

func main() {
	defer client.Close()
	_ = client.Set("name", "lhy", time.Duration(time.Second*1))
	result := client.Get("name")
	fmt.Println(result.Val())
}
